<?php

namespace App\Jobs;

use App\CustomMsgReceive;
use App\Third\XcxCustom;


class ReceiveGiteeMessage extends Job
{
    // 0:表示接收, 1:表示回复, 2:表示系统下发消息到企业号
    private $note;
    private $noteable_id;
    private $per_iid;


    public function __construct($note, $noteable_id, $per_iid) {
        $this->note = $note;
        $this->noteable_id = $noteable_id;
        $this->per_iid = $per_iid;
    }

    public function handle() {
        // 去 # 号
        $number = substr($this->per_iid, 1);

        // 查找该 number 下的消息
        $receive = CustomMsgReceive::where('number', $number)->first();
        if ($receive) {
            // 下发到企业号的回复内容
            $xcxCustom = new XcxCustom();
            $xcxCustom->reply($receive->fromUserName, $this->note);
        }
    }
}
